﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.Controls
{
    [TemplateVisualState(GroupName = "IsOpen", Name = "Open")]
    [TemplateVisualState(GroupName = "IsOpen", Name = "Close")]
    public class Expander : HeaderedContentControl
    {
        public readonly static DependencyProperty IsOpenProperty = DependencyProperty.Register("IsOpen", typeof(bool), typeof(Expander), new PropertyMetadata(true, (e, s) =>
        {
            (e as Expander).GoToState();
        }));
        public bool IsOpen
        {
            get
            {
                return (bool)this.GetValue(Expander.IsOpenProperty);
            }
            set
            {
                this.SetValue(Expander.IsOpenProperty, value);
            }
        }
        public Expander()
        {
            this.DefaultStyleKey = typeof(Expander);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.GoToState();

        }
        private void GoToState()
        {
            if (this.IsOpen)
            {
                VisualStateManager.GoToState(this, "Open", false);
            }
            else
            {
                VisualStateManager.GoToState(this, "Close", false);
            }
        }
    }
}
